package lib.self.ex.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import androidx.annotation.Nullable;

/**
 * description: 开机页
 * author: Steven Xiao
 * date: 2017/5/8
 */
public abstract class SplashActivityEx extends ActivityEx {

    protected Handler mHandler;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
            finish();
            return;
        }

    }

    @SuppressLint("HandlerLeak")
    @Override
    public void initData() {
        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                goPast();
                finish();
            }
        };
    }

    @Override
    public void initTitleBar() {
    }

    @Override
    public void findViews() {
    }

    @Override
    public void setViewsValue() {
    }

    protected void goNext() {
        //FIXME 启动页没有过多的初始化 这段代码无用
//        if (getDecorView().getViewTreeObserver().isAlive()) {
//            getDecorView().getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
//                @Override
//                public boolean onPreDraw() {
//                    mHandler.sendEmptyMessageDelayed(0, getPastDelay());
//                    getDecorView().getViewTreeObserver().removeOnPreDrawListener(this);
//                    return true;
//                }
//            });
//        } else {
//            mHandler.sendEmptyMessageDelayed(0, getPastDelay());
//        }
        mHandler.sendEmptyMessageDelayed(0, getPastDelay());
    }

    /**
     * 跳转处理
     */
    protected abstract void goPast();

    @Override
    protected void startInAnim() {
    }

    @Override
    protected void startOutAnim() {
    }

    /**
     * @return 毫秒
     */
    protected long getPastDelay() {
        return 1000;
    }
}
